<%@ page language="java" import="com.gxuwz.medical.domain.person.*" %>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%--引入自定义标签--%>
<%@ taglib prefix="tags" uri="/WEB-INF/tld/custom.tld" %>
<%@ include file="/common/base.jsp"%>
<%
 //所在乡镇行政区域编码
 String town=(String)session.getAttribute("agencode");
Institution inst=new Institution();
inst.setAgencode(town);
inst.loadDB();
town=inst.getArea().getAreacode();
 System.out.print("town:"+town);
 AreaDao areaDao =new AreaDao();
 //根据乡镇编码获取所有村
 List<Area> areaList=areaDao.findChildArea(town, 3);
 List<Area> areaGroup=areaDao.findChildArea(town, 4);
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<base href="<%=basePath%>">

<title>参合缴费登记</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/admin.css">
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/admin.js"></script>
<!-- 引入第三方弹出对话框JS组件 -->
<script type="text/javascript" src="third/layer/layer.js"></script>
<script type="text/javascript">
//选择不同的村组
function chooseGroup(){
	var val=$("#village").val();
	$.ajax({
		   type: "POST",
		   url: "<%=path%>/system/AreaServlet?m=groupList",
		   data: {"villageID":val},
		   dataType:"json",
		   success: function(data){
			 $("#group").empty();
			 $("#group").append("<option value=''>默认全部</option>");
		     $.each(data,function(i,val){
		    	 $("#group").append("<option value='"+val.areacode+"'>"+val.areaname+"</option>");
		     });
		   }
		});
}
</script>
</head>
<body>
	<form method="post" action="<%=path%>/system/PaymentServlet?m=list" id="listform">
		<div class="panel admin-panel">
			<div class="panel-head">
				<strong class="icon-reorder">参合缴费登记</strong>
			</div>
			<div class="padding border-bottom">
				<ul class="search" style="padding-left:10px;">
				   <li>所在村:<select id="village" name="village" class="input"
						   style="width:150px; line-height:17px;display:inline-block" 
							onchange="chooseGroup();">
					        <option value="">默认全部</option>
							<% for(Area m:areaList) {%>				
							<option data="<%=m.getParent().getAreaname() %>" value="<%=m.getAreacode()%>"><%=m.getAreaname() %></option>
							<% } %>
						</select>
						所在组：
						<select id="group" name="group" class="input" style="width:150px; line-height:17px;display:inline-block"  >
								<option value="">默认全部</option>
								<% for(Area m:areaGroup) {%>				
							<option data="<%=m.getParent().getAreaname() %>" value="<%=m.getAreacode()%>"><%=m.getAreaname() %></option>
							<% } %>
							</select>
						</li>
					<li>关键字（姓名）：</li>
					<li><input type="text" placeholder="请输入户主姓名" name="keywords"
						class="input"
						style="width:150px; line-height:17px;display:inline-block" />
						 <button class="button border-main icon-search" type="submit"> 搜索</button></li>
					
				</ul>
			</div>
			<table class="table table-hover text-center">
				<tr>
					<th>序号</th>
					<th>家庭编号</th>
					<th>农合证号</th>
					<th>个人姓名</th>
					<th>性别</th>
					<th>出生年月</th>
					<th>年龄</th>
					<th>身份证号</th>
					<th>乡镇/村/组</th>
					<th>操作</th>
				</tr>
				<%
					String pageNo = request.getParameter("pageNo");
				String sqll="select * from t_person,t_family  where t_person.famicode=t_family.famicode ";
				int key=0;
				Object[] params =new Object[4];
				String village=request.getParameter("village");
				if(village!=null&&!village.equals("")) {
					sqll+="and t_family.village=? ";
					params[key]=village;
					key++;
					
				}
				String group=request.getParameter("group");
				if(group!=null&&!group.equals("")) {
					sqll+="and t_family.groupNo=? ";
					params[key]=group;
					key++;
				}
				String keywords=request.getParameter("keywords");
				if(keywords!=null&&!keywords.equals("")) {
					params[key]=keywords;
					sqll+="and t_person.persname=?";
					key++;
				}
					int p = pageNo == null ? 1 : Integer.parseInt(pageNo);
					PersonDao dao = new PersonDao();
					String sql = "select * from t_person where 1=1 ";
					Page pageBean=null;
					if(key>0){
						sql=sqll;
						List<Person> list=dao.queryOjects(sql,params);
						pageBean=new Page(1,1,list);
					}
					else{
						params=null;
						pageBean = dao.queryOjectsByPage(sql, params, p,
							Constant.ROW);
					}
				%>
				<%
					for (int i = 0; i < pageBean.getDatas().size(); i++) {

						Person model = (Person) pageBean.getDatas().get(i);
						if(!model.getFamily().getTown().getAreacode().equals(town)) continue;
						if(!model.getRelation().equals("1")) continue;
				%>
				<tr>

					<td ><%=i+1 %></td>
					
					<td><%=model.getFamily().getFamicode() %></td>
					<td><%=model.getPerscode() %></td>
					<td><%=model.getPersname() %></td>
					
					<td>
					<% if("1".equals(model.getSex())){ %>
					             男
					      <%}else if("2".equals(model.getSex())){%>
					        女
					      <%} %></td>
					<td><%=model.getBirthday() %></td>
					<td><%=model.getAge() %></td>
					<td>
					<tags:hide size="4" value="<%=model.getCardID() %>" start="12"/></td>
					<td><%=model.getFamily().getTown().getAreaname()+model.getFamily().getVillage().getAreaname()+model.getFamily().getGroupNo().getAreaname() %></td>
					<td><div class="button-group">
							<a class="button border-main"
								href="<%=path%>/system/PaymentServlet?m=gopay&id=<%=model.getFamily().getFamicode()%>"><span
								class="icon-edit"></span> 去缴费</a>
								
						</div></td>
				</tr>
				<%
					}
				%>
			</table>
			<div class="pagelist">
				<%
					if (pageBean.hasPre()&&key==0) {
				%>
				<a
					href="<%=path%>/system/PaymentServlet?m=list&pageNo=<%=pageBean.prePage()%>">上一页</a>
				<%
					} else {
				%>
				<a href="javascript:void(0)">上一页</a>
				<%
					}
				%>
				<%
					List<Integer> linkNums = pageBean.linkLumbers();
					for (int num : linkNums) {
						if (pageBean.isCurrent(num)) {
				%>
				<span class="current"><%=num%></span>
				<%
					} else {
				%>
				<a href="<%=path%>/system/PaymentServlet?m=list&pageNo=<%=num%>"><%=num%></a>
				<%
					}
					}
				%>
				<%
					if (pageBean.hasNext()&&key==0) {
				%>
				<a
					href="<%=path%>/system/PaymentServlet?m=list&pageNo=<%=pageBean.lastPage()%>">下一页</a>
				<%
					} else {
				%>
				<a href="javascript:void(0)">下一页</a>
				<%
					}
				if(key==0){
					%>
					<a
						href="<%=path%>/system/PaymentServlet?m=list&pageNo=<%=pageBean.getPages()%>">尾页</a>
						<%
					}
					else {
						%>
						<a href="javascript:void(0)">尾页</a>
						<%
						}
						%>
			</div>
		</div>
	</form>

</body>
</html>
